import { getMenuChildren } from "@/api/menu";
import { ProFormOption } from "tdesign-pro-component";

export const createMenuFormOption: ProFormOption[] = [
    {
        name: 'name',
        label: '组件名',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件名' }
        ]
    },
    {
        name: 'path',
        label: '组件路径',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件路径' }
        ]
    },
    {
        name: 'title',
        label: '组件标题',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件路径' }
        ]
    },
    {
        name: 'icon',
        label: '组件图标',
        formItemProps: {
            labelAlign: 'top'
        }
    },
    {
        name: 'auth',
        label: '是否认证',
        formItemProps: {
            labelAlign: 'top'
        },
        type: 'radio',
        initalValue: true,
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'permission',
        label: '权限标识',
        formItemProps: {
            labelAlign: 'top'
        },
    },
    {
        name: 'button',
        label: '是否为按钮',
        formItemProps: {
            labelAlign: 'top'
        },
        type: 'radio',
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'show',
        label: '是否显示',
        formItemProps: {
            labelAlign: 'top'
        },
        initalValue: true,
        type: 'radio',
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'parentId',
        label: '父级菜单',
        type: 'treeSelect',
        data: async () => {
            const data = await getMenuChildren();
            return [{label: '系统', value: -1, children: [...data]}]
        },
        rules:[ 
            {required: true, message: '请选择父级菜单'}
        ],
        selectProps: {
            formItemProps: {
                labelAlign: 'top'
            }
        }
    },
    {
        name: 'orderNum',
        label: '排序',
        formItemProps: {
            labelAlign: 'top'
        }
    }
]

export const updateMenuFormOption: ProFormOption[] = [
    {
        name: 'id',
        label: '索引',
        disabled: true,
        formItemProps: {
            labelAlign: 'top'
        }
    },
    {
        name: 'name',
        label: '组件名',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件名' }
        ]
    },
    {
        name: 'path',
        label: '组件路径',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件路径' }
        ]
    },
    {
        name: 'title',
        label: '组件标题',
        formItemProps: {
            labelAlign: 'top'
        },
        rules: [
            { required: true, message: '请输入组件路径' }
        ]
    },
    {
        name: 'icon',
        label: '组件图标',
        formItemProps: {
            labelAlign: 'top'
        }
    },
    {
        name: 'auth',
        label: '是否认证',
        formItemProps: {
            labelAlign: 'top'
        },
        type: 'radio',
        initalValue: true,
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'permission',
        label: '权限标识',
        formItemProps: {
            labelAlign: 'top'
        },
    },
    {
        name: 'button',
        label: '是否为按钮',
        formItemProps: {
            labelAlign: 'top'
        },
        type: 'radio',
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'show',
        label: '是否显示',
        formItemProps: {
            labelAlign: 'top'
        },
        initalValue: true,
        type: 'radio',
        data: [
            { label: '是', value: true },
            { label: '否', value: false }
        ]
    },
    {
        name: 'parentId',
        label: '父级菜单',
        formItemProps: {
            labelAlign: 'top'
        },
        type: 'treeSelect',
        data: async () => {
            const data = await getMenuChildren();
            return [{label: '系统', value: -1, children: [...data]}]
        },
    },
    {
        name: 'orderNum',
        label: '排序',
        formItemProps: {
            labelAlign: 'top'
        }
    }
]